#src/app.py

from flask import Flask

from config import app_config
from models import db, bcrypt

# import user_api blueprint
from views.Home import home_api as home_blueprint
from views.UserView import user_api as user_blueprint
from views.BlogpostView import blogpost_api as blogpost_blueprint
from views.MarketView import market_api as market_blueprint
from views.CurrencyView import currency_api as currency_blueprint
from views.PortfolioView import portfolio_api as portfolio_blueprint

def create_app(env_name):
  """
  Create app
  """
  
  # app initiliazation
  app = Flask(__name__)

  app.config.from_object(app_config[env_name])

  # initializing bcrypt and db
  bcrypt.init_app(app)
  db.init_app(app)

  app.register_blueprint(home_blueprint, url_prefix='/')
  app.register_blueprint(user_blueprint, url_prefix='/api/users')
  app.register_blueprint(blogpost_blueprint, url_prefix='/api/blogposts')
  app.register_blueprint(market_blueprint, url_prefix='/api/markets')
  app.register_blueprint(currency_blueprint, url_prefix='/api/currencies')  
  app.register_blueprint(portfolio_blueprint, url_prefix='/api/portfolios')

  return app

